#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	
	int nLen;
	cin>>nLen;
	vector<int> vecPrices;
	int nMinPrice=1e4+10;
	int nRet=0;
	vecPrices.resize(nLen);
	for(int i=1;i<=nLen;++i){
		cin>>vecPrices[i];
		nRet=max(nRet,vecPrices[i]-nMinPrice);
		nMinPrice=min(nMinPrice,vecPrices[i]);
	}
	cout<<nRet;
	return 0;
}
